package com.shawn.integeration.async.config;

import com.shawn.integeration.async.exception.AsyncExceptionHandler;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.Resource;
import java.util.concurrent.Executor;

/**
 * @author shawn
 * @description: 异步处理配置类
 * @date 2024/1/15
 */
@Configuration
public class AsyncConfig implements AsyncConfigurer {
    @Resource
    private ThreadPoolTaskExecutor executor;
    @Override
    public Executor getAsyncExecutor() {
        executor.initialize();
        return executor;
    }
    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new AsyncExceptionHandler();
    }
}
